package com.zzty.servlet;

import com.zzty.common.Log;
import com.zzty.service.ComService;
import com.zzty.serviceimpl.ComServiceImpl;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name="ComQuesServlet",urlPatterns ="/ComQuesServlet")
public class ComQuesServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String method=request.getParameter("method");
        if("getContentByDate".equals(method)){
            getContentByDate(request,response);
        }
    }
    protected void getContentByDate(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String date=request.getParameter("date");
        ComService tes=new ComServiceImpl();
        String content=tes.getContentByDate(date);
        ObjectMapper mapper = new ObjectMapper();
        String json=null;
        if(content==null){
            json = mapper.writeValueAsString("今日没有作业！");
        }
        else{
            json = mapper.writeValueAsString(content);
        }

        PrintWriter out = response.getWriter();
        out.write(json);
        out.flush();
        out.close();
    }
}
